import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import store from '../store';

console.log(`language.js ==>${store}`);

const en = require('../assets/json/en.json');
const ch = require('../assets/json/ch.json');

const resources = {
  en: {
    translation: en,
  },
  ch: {
    translation: ch,
  },
};
let curLanguage = store.languageStore.language;

function changeLanguage(curLanguage: string) {
  i18n.use(initReactI18next).init({
    resources,
    lng: curLanguage,
    fallbackLng: 'en',
    keySeparator: false, // we do not use keys in form messages.welcome
    interpolation: {
      escapeValue: false, // react already safes from xss
    },
  });
}
changeLanguage(curLanguage);
export { changeLanguage, i18n };
